package com.sia.springcloud.protocol.model;

import com.sia.springcloud.model.Point;
import lombok.Data;

import javax.print.attribute.standard.MediaSize;
import java.io.Serializable;

/**
 * @Author: Sirius
 * @Date: 2021/10/3 20:16
 * @Description: 111
 **/
@Data
public class ModbusPoint implements Serializable {
    private Integer id;
    private Integer collect;
    private Integer deviceId;
    private String protocolName;
    private String pointName;
    private Integer frequency;
    private Integer sendFrequency;
    private String metricName;
    private String target;
    private String domain;
    private String scale;
    private Integer functionCode;
    private Integer slaveId;
    private Integer bit;
    private Integer offset;
    private Integer length;
    private Integer pattern;
    private String typeStr;

    private static final long serialVersionUID = 1L;

    /**
     * 将Modbus变量对象转换成协议变量对象
     *
     * @param modbusPoint
     * @return
     */
    public static Point convert(ModbusPoint modbusPoint) {
        Point point = new Point();

        point.setId(modbusPoint.getId());
        point.setCollect(modbusPoint.getCollect());
        point.setDeviceId(modbusPoint.getDeviceId());
        point.setProtocolName(modbusPoint.getProtocolName());
        point.setPointName(modbusPoint.getPointName());
        point.setFrequency(modbusPoint.getFrequency());
        point.setSendFrequency(modbusPoint.getSendFrequency());
        point.setMetricName(modbusPoint.getMetricName());
        point.setTarget(modbusPoint.getTarget());
        point.setDomain(modbusPoint.getDomain());
        point.setScale(modbusPoint.getScale());
        point.setFunctionCode(modbusPoint.getFunctionCode());
        point.setSlaveId(modbusPoint.getSlaveId());
        point.setBit(modbusPoint.getBit());
        point.setOffset(modbusPoint.getOffset());
        point.setLength(modbusPoint.getLength());
        point.setPattern(modbusPoint.getPattern());
        point.setVarStr1(modbusPoint.getTypeStr());

        return point;
    }

    /**
     * 将Protocol变量对象转换成Modbus变量对象
     *
     * @param point
     * @return
     */
    public static ModbusPoint reconvert(Point point) {
        ModbusPoint modbusPoint = new ModbusPoint();
        modbusPoint.setId(point.getId());
        modbusPoint.setCollect(point.getCollect());
        modbusPoint.setDeviceId(point.getDeviceId());
        modbusPoint.setProtocolName(point.getProtocolName());
        modbusPoint.setPointName(point.getPointName());
        modbusPoint.setFrequency(point.getFrequency());
        modbusPoint.setSendFrequency(point.getSendFrequency());
        modbusPoint.setMetricName(point.getMetricName());
        modbusPoint.setTarget(point.getTarget());
        modbusPoint.setDomain(point.getDomain());
        modbusPoint.setScale(point.getScale());
        modbusPoint.setFunctionCode(point.getFunctionCode());
        modbusPoint.setSlaveId(point.getSlaveId());
        modbusPoint.setBit(point.getBit());
        modbusPoint.setOffset(point.getOffset());
        modbusPoint.setLength(point.getLength());
        modbusPoint.setPattern(point.getPattern());
        modbusPoint.setTypeStr(point.getVarStr1());

        return modbusPoint;
    }

}
